package com.sg.service.base.app.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sg.common.util.CommonFunctionHelper;
import com.sg.dto.base.app.req.*;
import com.sg.entity.OmsTargetTimingTaskDispatch;
import com.sg.service.base.app.MOmsTargetTimingTaskDispatchService;
import com.wicket.okrapp.common.annotations.BanAuto;
import com.wicket.okrapp.common.dto.FieldInfo;
import com.wicket.okrapp.common.exception.BizException;
import com.wicket.okrapp.dal.mapper.mbg.OmsTargetTimingTaskDispatchMapper;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author ：
 * @version 1.0
 * @since 2022/1/19 15:39
 */
@Service
public class MOmsTargetTimingTaskDispatchServiceImpl
        extends ServiceImpl<OmsTargetTimingTaskDispatchMapper, OmsTargetTimingTaskDispatch>
        implements MOmsTargetTimingTaskDispatchService {

    @Autowired
    OmsTargetTimingTaskDispatchMapper omsTargetTimingTaskDispatchMapper;

    /**
     * 3-2-09更新定时任务调度[3186]
     * gen by moon at 5/13/2023, 3:13:56 PM
     */
    @Trace(operationName = "3-2-09更新定时任务调度")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    @BanAuto
    public boolean refreshTimerTaskPlan(OmsTargetTimingTaskDispatch omsTargetTimingTaskDispatch) {
//     UpdateWrapper<OmsTargetTimingTaskDispatch> uw = new UpdateWrapper<>();
//        uw.eq("timing_task_dispatch_id",omsTargetTimingTaskDispatch.getTimingTaskDispatchId());
//        uw.setSql("standby_field3 = standby_field3 + " + omsTargetTimingTaskDispatch.getStandbyField3());//ADD_NUMERICAL
//        omsTargetTimingTaskDispatch.setStandbyField3(null);
//        super.update(omsTargetTimingTaskDispatch,uw);
        return super.updateById(omsTargetTimingTaskDispatch);
    }

    /**
     * 3-2-09查询定时任务调度详情[3187]
     * gen by moon at 3/30/2023, 12:39:23 PM
     */
    @Trace(operationName = "3-2-09查询定时任务调度详情")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public OmsTargetTimingTaskDispatch queryTimerTaskPlanDetail(QueryTimerTaskPlanDetailReq reqDto) {

        try {
            reqDto.setIsValid("FALSE");
            QueryWrapper<OmsTargetTimingTaskDispatch> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<OmsTargetTimingTaskDispatch> retList = super.list(queryWrapper);
            if (retList != null && retList.size() > 0) {
                OmsTargetTimingTaskDispatch retData = retList.get(0);

                return retData;
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * 3-2-09新增定时任务调度[3191]
     * gen by moon at 10/15/2022, 10:05:37 PM
     */
    @Trace(operationName = "3-2-09新增定时任务调度")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String addTimerTaskPlan(OmsTargetTimingTaskDispatch omsTargetTimingTaskDispatch) {
        omsTargetTimingTaskDispatch.setTimingTaskDispatchId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
        omsTargetTimingTaskDispatch.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        omsTargetTimingTaskDispatch.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        omsTargetTimingTaskDispatch.setIsValid("FALSE");
        if (super.save(omsTargetTimingTaskDispatch)) {
            return omsTargetTimingTaskDispatch.getTimingTaskDispatchId();
        } else {
            return "-1";
        }

    }

    /**
     * 3-2-09批量增定时任务调度[3200]
     * gen by moon at 10/15/2022, 10:05:38 PM
     */
    @Trace(operationName = "3-2-09批量增定时任务调度")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchAddTimerTaskPlan(List<OmsTargetTimingTaskDispatch> omsTargetTimingTaskDispatch) {

        if (omsTargetTimingTaskDispatch == null || omsTargetTimingTaskDispatch.size() == 0) {
            return false;
        }

        return super.saveBatch(omsTargetTimingTaskDispatch.stream().map(item -> {
            item.setTimingTaskDispatchId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
            item.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
            item.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
            item.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
            item.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
            item.setIsValid("FALSE");
            item.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
            item.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
            return item;
        }).collect(Collectors.toList()));
    }

    /**
     * 3-2-09查询定时任务调度列表[3261]
     * gen by moon at 10/25/2022, 9:56:17 AM
     */
    @Trace(operationName = "3-2-09查询定时任务调度列表")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OmsTargetTimingTaskDispatch> queryTimerTaskPlanList(QueryTimerTaskPlanListReq reqDto) {

        try {
            QueryWrapper<OmsTargetTimingTaskDispatch> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");

            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsTargetTimingTaskDispatch.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            queryWrapper.orderByDesc("operate_time");
            return ((List<OmsTargetTimingTaskDispatch>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * 3-2-09批量删定时任务调度[3277]
     * gen by moon at 10/15/2022, 10:05:43 PM
     */
    @Trace(operationName = "3-2-09批量删定时任务调度")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchDeleteTimerTaskPlan(List<String> reqDto) {

        if (reqDto == null || reqDto.size() == 0) {
            return false;
        }

        return super.removeByIds(reqDto);
    }

    /**
     * 3-2-09删除定时任务调度[3279]
     * gen by moon at 10/15/2022, 10:05:45 PM
     */
    @Trace(operationName = "3-2-09删除定时任务调度")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteTimerTaskPlan(String timingTaskDispatchId) {

        return super.removeById(timingTaskDispatchId);
    }

    /**
     * 3-2-09批量查询定时任务调度[3531]
     * gen by moon at 10/15/2022, 10:05:48 PM
     */
    @Trace(operationName = "3-2-09批量查询定时任务调度")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OmsTargetTimingTaskDispatch> batchQueryTimerTaskPlan(BatchQueryTimerTaskPlanReq reqDto) {

        try {
            QueryWrapper<OmsTargetTimingTaskDispatch> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
            if (reqDto.getTimerTaskPlanList() == null || reqDto.getTimerTaskPlanList().isEmpty()) {
                return new ArrayList<>();
            }
            queryWrapper.in("add_rule_info_id", reqDto.getTimerTaskPlanList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsTargetTimingTaskDispatch.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsTargetTimingTaskDispatch>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * 3-2-09执行悬停查调度任务（悬停）[4310]
     * gen by moon at 9/5/2022, 1:03:54 AM
     */
    @Trace(operationName = "3-2-09执行悬停查调度任务（悬停）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @BanAuto
    public OmsTargetTimingTaskDispatch implementSpinLockCheckTimingTask(ImplementSpinLockCheckTimingTaskReq reqDto) {
        try {
            long count = 2000;
            while (true) {
                if (count == 0) {
                    break;
                }
                reqDto.setIsValid("FALSE");
                QueryWrapper<OmsTargetTimingTaskDispatch> queryWrapper = new QueryWrapper<>();
                Map<String, Object> fieldInfoMap = null;
                fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
                CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
                queryWrapper.orderByDesc("create_time");
                if (super.list(queryWrapper) != null && super.list(queryWrapper).size() > 0) {
                    return super.list(queryWrapper).get(0);
                }
                count--;
                Thread.sleep(10);
            }
            throw new BizException("-1", false);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }

    }

    /**
     * M3-2-09一键删除定时任务调度测试验证数据[4433]
     * gen by moon at 10/15/2022, 10:05:53 PM
     */
    @Trace(operationName = "M3-2-09一键删除定时任务调度测试验证数据")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean autoDeleteTimingTaskDispatchTest(List<String> reqDto) {

        if (reqDto == null || reqDto.size() == 0) {
            return false;
        }

        return super.removeByIds(reqDto);
    }

    /**
     * M3-2-09查询定时任务调度测试列表[4453]
     * gen by moon at 10/15/2022, 10:05:54 PM
     */
    @Trace(operationName = "M3-2-09查询定时任务调度测试列表")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OmsTargetTimingTaskDispatch> queryTimingTaskDispatchTestList(QueryTimingTaskDispatchTestListReq reqDto) {

        try {
            QueryWrapper<OmsTargetTimingTaskDispatch> queryWrapper = new QueryWrapper<>();


            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsTargetTimingTaskDispatch.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsTargetTimingTaskDispatch>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * M3-生成定时任务入参数据集融合（特殊方法）[4699]
     * gen by moon at 10/15/2022, 10:05:54 PM
     */
    @Trace(operationName = "M3-生成定时任务入参数据集融合（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String addTimeTaskCollectionsAggregation(OmsTargetTimingTaskDispatch omsTargetTimingTaskDispatch) {

        if (super.save(omsTargetTimingTaskDispatch)) {
            return omsTargetTimingTaskDispatch.getTimingTaskDispatchId();
        } else {
            return "-1";
        }

    }

    /**
     * 3-2-09批量改定时任务调度[5011]
     * gen by moon at 10/26/2022, 10:48:31 AM
     */
    @Trace(operationName = "3-2-09批量改定时任务调度")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchUpdateTimerTaskPlan(List<OmsTargetTimingTaskDispatch> omsTargetTimingTaskDispatch) {

        if (omsTargetTimingTaskDispatch == null || omsTargetTimingTaskDispatch.size() == 0) {
            return false;
        }
        return super.saveOrUpdateBatch(omsTargetTimingTaskDispatch);

    }

    /**
     * 3-2-09批量查询定时任务调度by行为编码[5088]
     * gen by moon at 11/3/2022, 10:56:29 PM
     */
    @Trace(operationName = "3-2-09批量查询定时任务调度by行为编码")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OmsTargetTimingTaskDispatch> batchQueryTimerTaskPlanActionCode(BatchQueryTimerTaskPlanActionCodeReq reqDto) {

        try {
            QueryWrapper<OmsTargetTimingTaskDispatch> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
            if (reqDto.getTimerTaskPlanActionCodeList() == null || reqDto.getTimerTaskPlanActionCodeList().isEmpty()) {
                return new ArrayList<>();
            }
            queryWrapper.in("dispatch_action_type_code", reqDto.getTimerTaskPlanActionCodeList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsTargetTimingTaskDispatch.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsTargetTimingTaskDispatch>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * 3-2-09批量查询异步调度by内容ID[5668]
     * gen by moon at 1/12/2023, 5:00:29 AM
     */
    @Trace(operationName = "3-2-09批量查询异步调度by内容ID")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OmsTargetTimingTaskDispatch> batchQueryAsynchronousSchedulingByContentID(BatchQueryAsynchronousSchedulingByContentIDReq reqDto) {

        try {
            QueryWrapper<OmsTargetTimingTaskDispatch> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
            reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
            if (reqDto.getAsynchronousSchedulingByContentIDList() == null || reqDto.getAsynchronousSchedulingByContentIDList().isEmpty()) {
                return new ArrayList<>();
            }
            queryWrapper.in("object_id", reqDto.getAsynchronousSchedulingByContentIDList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsTargetTimingTaskDispatch.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsTargetTimingTaskDispatch>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * M3查询定时任务调度测试详情[6286]
     * gen by moon at 4/15/2023, 9:03:20 PM
     */
    @Trace(operationName = "M3查询定时任务调度测试详情")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public OmsTargetTimingTaskDispatch queryTimingTaskDispatchTestDetail(QueryTimingTaskDispatchTestDetailReq reqDto) {

        try {

            QueryWrapper<OmsTargetTimingTaskDispatch> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<OmsTargetTimingTaskDispatch> retList = super.list(queryWrapper);
            if (retList != null && retList.size() > 0) {
                OmsTargetTimingTaskDispatch retData = retList.get(0);

                return retData;
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * 3-2-09批量查定时任务调度By归属对象Ids[6557]
     * gen by moon at 5/11/2023, 4:26:41 AM
     */
    @Trace(operationName = "3-2-09批量查定时任务调度By归属对象Ids")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OmsTargetTimingTaskDispatch> batchQueryTimerTaskPlanListByIds(BatchQueryTimerTaskPlanListByIdsReq reqDto) {

        try {
            QueryWrapper<OmsTargetTimingTaskDispatch> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
            if (reqDto.getTimerTaskPlanList() == null || reqDto.getTimerTaskPlanList().isEmpty()) {
                return new ArrayList<>();
            }
            queryWrapper.in("object_id", reqDto.getTimerTaskPlanList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsTargetTimingTaskDispatch.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            queryWrapper.orderByDesc("standby_field2");
            queryWrapper.orderByDesc("operate_time");
            return ((List<OmsTargetTimingTaskDispatch>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * 3-2-09查询定时任务调度列表by调度ID[6594]
     * gen by moon at 5/11/2023, 8:24:09 PM
     */
    @Trace(operationName = "3-2-09查询定时任务调度列表by调度ID")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OmsTargetTimingTaskDispatch> queryTimerTaskPlanByPlanIdList(QueryTimerTaskPlanByPlanIdListReq reqDto) {

        try {
            QueryWrapper<OmsTargetTimingTaskDispatch> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
            if (reqDto.getTimerTaskPlanList() == null || reqDto.getTimerTaskPlanList().isEmpty()) {
                return new ArrayList<>();
            }
            queryWrapper.in("timing_task_dispatch_id", reqDto.getTimerTaskPlanList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsTargetTimingTaskDispatch.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsTargetTimingTaskDispatch>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * 3-2-09更新定时任务调度数值自动加[6681]
     * gen by moon at 5/14/2023, 3:27:18 PM
     */
    @Trace(operationName = "3-2-09更新定时任务调度数值自动加")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    @BanAuto
    public boolean refreshTimerTaskDispatchNumAtuoAdd(OmsTargetTimingTaskDispatch omsTargetTimingTaskDispatch) {
        UpdateWrapper<OmsTargetTimingTaskDispatch> uw = new UpdateWrapper<>();
        uw.eq("timing_task_dispatch_id", omsTargetTimingTaskDispatch.getTimingTaskDispatchId());
        uw.setSql("standby_field5 = standby_field5 + " + omsTargetTimingTaskDispatch.getStandbyField5());//ADD_NUMERICAL
        omsTargetTimingTaskDispatch.setStandbyField3(null);
        super.update(omsTargetTimingTaskDispatch, uw);
        return super.updateById(omsTargetTimingTaskDispatch);

    }

    /**
     * 3-2-09查询MQ任务调度队列列表[7117]
     * gen by moon at 6/3/2023, 12:12:43 AM
     */
    @Trace(operationName = "3-2-09查询MQ任务调度队列列表")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OmsTargetTimingTaskDispatch> queryMqTaskPlanQueueList(QueryMqTaskPlanQueueListReq reqDto) {

        try {
            QueryWrapper<OmsTargetTimingTaskDispatch> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");

            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsTargetTimingTaskDispatch.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            queryWrapper.orderByAsc("appoint_simple_mq_value");
            queryWrapper.orderByDesc("operate_time");
            return ((List<OmsTargetTimingTaskDispatch>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * 3-2-09查询定时任务调度列表by自动安排时间排序[7447]
     * gen by moon at 9/25/2023, 6:42:00 PM
     */
    @Trace(operationName = "3-2-09查询定时任务调度列表by自动安排时间排序")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OmsTargetTimingTaskDispatch> queryTimerTaskPlanByAutoPlanTimeList(QueryTimerTaskPlanByAutoPlanTimeListReq reqDto) {

        try {
            QueryWrapper<OmsTargetTimingTaskDispatch> queryWrapper = new QueryWrapper<>();


            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsTargetTimingTaskDispatch.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            queryWrapper.orderByAsc("auto_plan_time");
            queryWrapper.orderByAsc("create_time");
            queryWrapper.orderByDesc("operate_time");
            return ((List<OmsTargetTimingTaskDispatch>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * M3修改定时任务调度测试[8286]
     * gen by moon at 1/8/2024, 1:33:50 PM
     */
    @Trace(operationName = "M3修改定时任务调度测试")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateTimingTaskDispatchTest(OmsTargetTimingTaskDispatch omsTargetTimingTaskDispatch) {
        omsTargetTimingTaskDispatch.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
        omsTargetTimingTaskDispatch.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        return super.updateById(omsTargetTimingTaskDispatch);
    }

    /**
     * 3-2-09查询定时任务调度列表by备用字段2[9490]
     * gen by moon at 5/2/2024, 2:41:36 AM
     */
    @Trace(operationName = "3-2-09查询定时任务调度列表by备用字段2")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OmsTargetTimingTaskDispatch> queryTimerTaskPlanByStandbyField2List(QueryTimerTaskPlanByStandbyField2ListReq reqDto) {

        try {
            QueryWrapper<OmsTargetTimingTaskDispatch> queryWrapper = new QueryWrapper<>();

            if (reqDto.getTimerTaskPlanList() == null || reqDto.getTimerTaskPlanList().isEmpty()) {
                return new ArrayList<>();
            }
            queryWrapper.in("standby_field2", reqDto.getTimerTaskPlanList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsTargetTimingTaskDispatch.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsTargetTimingTaskDispatch.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsTargetTimingTaskDispatch>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

}

